Return to start page

Systems/Character/Struct Revival.j

Code

		
1			library AStructSystemsCharacterRevival requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, ALibraryCoreInterfaceMisc, AStructSystemsCharacterAbstractCharacterSystem
2
3 struct ARevival extends AAbstractCharacterSystem
4 //static start members
5 private static boolean m_showDialog
6 //dynamic members
7 private real m_time
8 private real m_x
9 private real m_y
10 private real m_facing
11 //members
12 private trigger m_revivalTrigger
13 private timer m_timer
14 private timerdialog m_timerDialog
15
16 //! runtextmacro optional A_STRUCT_DEBUG("\"ARevival\"")
17
18 //dynamic members
19
20 public method setTime takes real time returns nothing
21 set this.m_time = time
22 endmethod
23
24 public method time takes nothing returns real
25 return this.m_time
26 endmethod
27
28 public method setX takes real x returns nothing
29 set this.m_x = x
30 endmethod
31
32 public method x takes nothing returns real
33 return this.m_x
34 endmethod
35
36 public method setY takes real y returns nothing
37 set this.m_y = y
38 endmethod
39
40 public method y takes nothing returns real
41 return this.m_y
42 endmethod
43
44 public method setFacing takes real facing returns nothing
45 set this.m_facing = facing
46 endmethod
47
48 public method facing takes nothing returns real
49 return this.m_facing
50 endmethod
51
52 //methods
53
54 public method enable takes nothing returns nothing
55 call super.enable()
56 call EnableTrigger(this.m_revivalTrigger)
57 if (TimerGetRemaining(this.m_timer) > 0.0) then
58 call PauseTimerBJ(false, this.m_timer)
59 if (thistype.m_showDialog) then //Der bersicht halber nicht in die Funktion bergeben
60 call TimerDialogDisplay(this.m_timerDialog, true)
61 endif
62 endif
63 endmethod
64
65 public method disable takes nothing returns nothing
66 call super.disable()
67 call DisableTrigger(this.m_revivalTrigger)
68 if (TimerGetRemaining(this.m_timer) > 0.0) then
69 call PauseTimerBJ(true, this.m_timer)
70 if (thistype.m_showDialog) then
71 call TimerDialogDisplay(this.m_timerDialog, false)
72 endif
73 endif
74 endmethod
75
76 private method revive takes nothing returns nothing
77 call ReviveHero(this.unit(), this.m_x, this.m_y, true)
78 call SetUnitFacing(this.unit(), this.m_facing)
79 endmethod
80
81 private static method timerFunctionRevival takes nothing returns nothing
82 local timer expiredTimer = GetExpiredTimer()
83 local thistype this = AHashTable.global().handleInteger(expiredTimer, "this")
84 call this.revive()
85 call this.end()
86 set expiredTimer = null
87 endmethod
88
89 private method start takes nothing returns nothing
90 call TimerStart(this.m_timer, this.m_time, false, function thistype.timerFunctionRevival)
91 if (thistype.m_showDialog) then
92 call TimerDialogDisplay(this.m_timerDialog, true)
93 endif
94 endmethod
95
96 private method end takes nothing returns nothing
97 call PauseTimer(this.m_timer) //Zur Sicherheit auch stoppen
98 if (thistype.m_showDialog) then
99 call TimerDialogDisplay(this.m_timerDialog, false)
100 endif
101 endmethod
102
103 private method createTimer takes nothing returns nothing
104 set this.m_timer = CreateTimer()
105 call AHashTable.global().setHandleInteger(this.m_timer, "this", this)
106 if (thistype.m_showDialog) then
107 set this.m_timerDialog = CreateTimerDialog(this.m_timer)
108 call TimerDialogSetTitle(this.m_timerDialog, GetModifiedPlayerName(this.user()))
109 //call TimerDialogDisplay(this.timerDialog, false) //test
110 endif
111 endmethod
112
113 private static method triggerActionRevival takes nothing returns nothing
114 local trigger triggeringTrigger = GetTriggeringTrigger()
115 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
116 if (this.m_time > 0.0) then
117 call this.start()
118 else
119 call this.revive()
120 endif
121 //set unmovable
122 set triggeringTrigger = null
123 endmethod
124
125 private method createRevivalTrigger takes nothing returns nothing
126 local event triggerEvent
127 local triggeraction triggerAction
128 set this.m_revivalTrigger = CreateTrigger()
129 set triggerEvent = TriggerRegisterUnitEvent(this.m_revivalTrigger, this.unit(), EVENT_UNIT_DEATH) //TriggerRegisterDeathEvent(this.revivalTrigger, this.unit())
130 set triggerAction = TriggerAddAction(this.m_revivalTrigger, function thistype.triggerActionRevival)
131 call AHashTable.global().setHandleInteger(this.m_revivalTrigger, "this", this)
132 set triggerEvent = null
133 set triggerAction = null
134 endmethod
135
136 public static method create takes ACharacter character returns thistype
137 local thistype this = thistype.allocate(character)
138 call this.createTimer()
139 call this.createRevivalTrigger()
140 return this
141 endmethod
142
143 private method destroyTimer takes nothing returns nothing
144 call PauseTimer(this.m_timer)
145 call AHashTable.global().destroyTimer(this.m_timer)
146 set this.m_timer = null
147 if (thistype.m_showDialog) then
148 call DestroyTimerDialog(this.m_timerDialog)
149 set this.m_timerDialog = null
150 endif
151 endmethod
152
153 private method destroyRevivalTrigger takes nothing returns nothing
154 call AHashTable.global().destroyTrigger(this.m_revivalTrigger)
155 set this.m_revivalTrigger = null
156 endmethod
157
158 public method onDestroy takes nothing returns nothing
159
160 call this.destroyTimer()
161 call this.destroyRevivalTrigger()
162 endmethod
163
164 public static method init takes boolean showDialog returns nothing
165 //static start members
166 set thistype.m_showDialog = showDialog
167 endmethod
168 endstruct
169
170 endlibrary